import 'package:dance_todo/objectbox.g.dart';
import 'package:objectbox/objectbox.dart';

@Entity()
class Record {
  @Id()
  int id = 0;

  //项目名称
  String? name;

  //计数
  int totalCount = 0;

  //完成
  int doneCount = 0;

  int eventId = 0;

  @Property(type: PropertyType.date) // Store as int in milliseconds
  DateTime? date;

  bool isEmpty() {
    return id == 0;
  }

  ///notice 查询记录
  static List<Record> queryRecords(Box<Record> recordBox, DateTime date) {
    int year = date.year;
    int month = date.month;
    int day = date.day;
    var from = DateTime(year, month, day);
    var to = from.add(Duration(days: 1));
    var query = recordBox
        .query(Record_.date
            .greaterOrEqual(from.millisecondsSinceEpoch)
            .and(Record_.date.lessOrEqual(to.millisecondsSinceEpoch)))
        .build();
    List<Record> records = query.find();
    return records;
  }
}
